<%--
  Created by IntelliJ IDEA.
  User: kangx
  Date: 2020/8/11
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加院系</title>
    <link rel="stylesheet" href="${AppPath}/css/font.css">
    <link rel="stylesheet" href="${AppPath}/css/index.css">
    <script src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${AppPath}/js/index.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" lay-fiter="deptForm">

            <div class="layui-form-item">
                <label for="deptName" class="layui-form-label">
                    <span class="x-red">*</span>院系名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="deptName" name="deptName" lay-fiter="deptName" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>


            <div class="layui-form-item">
                <label for="empId" class="layui-form-label">
                    <span class="x-red">*</span>院系主管
                </label>
                <div class="layui-input-inline">
                    <select name="empId" lay-verify="required" lay-filter="deptId" id="empId">
                        <option value="">请选择</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>


            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script>


    layui.use('form',function(){
        var form = layui.form;
        layui.$.ajax({
            url:"${AppPath}/dept/findZg",
            type:"post",
            success:function(resp){
                layui.$.each(resp,function (index,emp) {
                    var str='<option value="'+emp.empId+'">'+emp.empName+'</option>';
                    layui.$("#empId").append(str)
                })
                form.render();
            }
        })

        // 监听提交按钮
        form.on('submit(add)', function(data){
            console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            layui.$.ajax({
                url:"${AppPath}/dept/add",
                data:data.field,
                type:"post",
                success:function (resp) {
                    // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    if (resp=='ok'){
                        layer.msg('添加成功！',{
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        },function(){
                            parent.location.reload();
                        });
                    }else{
                        layer.msg('请稍后再试！', {
                            icon: 2,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });


</script>
</body>
</html>
